#include "PreCompiledHeader.h"
#include "GameState_Asteroid.hpp"
#include "System.hpp"
#include "Renderer.hpp"
#include "Collision.h"
#include "Vector2D.h"
#include "Timer.h"
#include <string>
#include <sstream>

#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

enum STATETYPE
{
	SINGLEPLAYER = 0,
	CLIENTMUTIPLYAER,
	SERVERMUTIPLAYER,
	QUITGAME
};

double bulletTime;
STATETYPE m_state;

/******************************************************************************/
/*!
	"Load" function of this state
*/
/******************************************************************************/
void MainMenuLoad(void)
{
	m_state  = SINGLEPLAYER; 	
}

/******************************************************************************/
/*!
	"Initialize" function of this state
*/
/******************************************************************************/
void MainMenuInit(void)
{
	
}

/******************************************************************************/
/*!
	"Update" function of this state
*/
/******************************************************************************/
void MainMenuUpdate(void)
{
	bulletTime +=  Timer::GetInstance()->GetDeltaTime();
	
	if (KEY_DOWN(VK_UP) && (bulletTime) > 0.1f)
	{
		bulletTime = 0;
		m_state = static_cast<STATETYPE>(m_state-1);
		if(m_state<0)
		{
			m_state =static_cast<STATETYPE>(0);
		}
	}

	if (KEY_DOWN(VK_DOWN) && (bulletTime) > 0.1f)
	{
		bulletTime = 0;
		m_state = static_cast<STATETYPE>(m_state+1);
		if(m_state>3)
		{
			m_state =static_cast<STATETYPE>(3);
		}
	}

	if(KEY_DOWN(VK_RETURN)&& (bulletTime) > 0.1f)
	{
		bulletTime = 0;
		switch(m_state)
		{
	
		case SINGLEPLAYER:
			gGameStateNext = GS_SINGLEPLAYER;
			break;

		case CLIENTMUTIPLYAER:
			gGameStateNext = GS_ASTEROIDS;
			break;

		case SERVERMUTIPLAYER:
			gGameStateNext = GS_SERVER;
			break;

		case QUITGAME:	
			gGameStateNext = GS_QUIT;
			break;

		}
	}

	
}

/******************************************************************************/
/*!
	Drawing of Aestroid onto buffer
*/
/******************************************************************************/
void MainMenuDraw(void)
{
	SYSTEM->GetRenderer()->PrepareToDraw();
	
	SYSTEM->GetRenderer()->DrawMenuBG();
	switch(m_state)
	{
	
	case SINGLEPLAYER:	
	SYSTEM->GetRenderer()->PrintTextWorld( "SINGLE PLAYER", -75, 0, RED, 500, 10);
	SYSTEM->GetRenderer()->PrintTextWorld( "MUTIPLAYER CLIENT", -75, -25, BLACK, 500, 10);
	SYSTEM->GetRenderer()->PrintTextWorld( "MUTIPLAYER SERVER", -75, -50, BLACK, 500, 10);
	SYSTEM->GetRenderer()->PrintTextWorld( "QUIT GAME", -75, -75, BLACK, 500, 10);
	break;

	case CLIENTMUTIPLYAER:	
	SYSTEM->GetRenderer()->PrintTextWorld( "SINGLE PLAYER", -75, 0, BLACK, 500, 10);
	SYSTEM->GetRenderer()->PrintTextWorld( "MUTIPLAYER CLIENT", -75, -25, RED, 500, 10);
	SYSTEM->GetRenderer()->PrintTextWorld( "MUTIPLAYER SERVER", -75, -50, BLACK, 500, 10);
	SYSTEM->GetRenderer()->PrintTextWorld( "QUIT GAME", -75, -75, BLACK, 500, 10);
	break;

	case SERVERMUTIPLAYER:
	SYSTEM->GetRenderer()->PrintTextWorld( "SINGLE PLAYER", -75, 0, BLACK, 500, 10);
	SYSTEM->GetRenderer()->PrintTextWorld( "MUTIPLAYER CLIENT", -75, -25, BLACK, 500, 10);
	SYSTEM->GetRenderer()->PrintTextWorld( "MUTIPLAYER SERVER", -75, -50, RED, 500, 10);
	SYSTEM->GetRenderer()->PrintTextWorld( "QUIT GAME", -75, -75, BLACK, 500, 10);
	break;


	case QUITGAME:	
	SYSTEM->GetRenderer()->PrintTextWorld( "SINGLE PLAYER", -75, 0, BLACK, 500, 10);
	SYSTEM->GetRenderer()->PrintTextWorld( "MUTIPLAYER CLIENT", -75, -25, BLACK, 500, 10);
	SYSTEM->GetRenderer()->PrintTextWorld( "MUTIPLAYER SERVER", -75, -50, BLACK, 500, 10);
	SYSTEM->GetRenderer()->PrintTextWorld( "QUIT GAME", -75, -75, RED, 500, 10);
	
	}
	
	SYSTEM->GetRenderer()->EndDraw();
}

/******************************************************************************/
/*!
	Free Asteroids
*/
/******************************************************************************/
void MainMenuFree(void)
{
	
}

/******************************************************************************/
/*!
	Unload Asteroids
*/
/******************************************************************************/
void MainMenuUnload(void)
{
	
}
